package com.eastmoney.emis.edda.infrastructure.report;

import org.springframework.util.StringUtils;

import java.lang.reflect.Field;
import java.util.List;

public class DDAReport {

    @Record(0)
    private String reportId;

    @Record(1)
    private String reportName;
    @Record(2)
    private String reportGenerationDate;
    @Record(3)
    private String reportingDate;
    @Record(4)
    private String recordCount;
    @Record(5)
    private String version;

    private List<DDAReportRecord> reportRecords;


    public DDAReport() {
    }

    public DDAReport(String data) {
        if (!StringUtils.hasText(data)) {
            return;
        }
        String[] dataArray = data.split(",");
        if (dataArray.length != 6) {
            return;
        }
        Field[] fields = this.getClass().getDeclaredFields();
        try {
            for (Field field : fields) {
                Record record = field.getAnnotation(Record.class);
                if (record == null) {
                    continue;
                }
                field.set(this, dataArray[record.value()].replace("\"", ""));
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }

    }

    public String getReportId() {
        return reportId;
    }

    public void setReportId(String reportId) {
        this.reportId = reportId;
    }

    public String getReportName() {
        return reportName;
    }

    public void setReportName(String reportName) {
        this.reportName = reportName;
    }

    public String getReportGenerationDate() {
        return reportGenerationDate;
    }

    public void setReportGenerationDate(String reportGenerationDate) {
        this.reportGenerationDate = reportGenerationDate;
    }

    public String getReportingDate() {
        return reportingDate;
    }

    public void setReportingDate(String reportingDate) {
        this.reportingDate = reportingDate;
    }

    public String getRecordCount() {
        return recordCount;
    }

    public void setRecordCount(String recordCount) {
        this.recordCount = recordCount;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public List<DDAReportRecord> getReportRecords() {
        return reportRecords;
    }

    public void setReportRecords(List<DDAReportRecord> reportRecords) {
        this.reportRecords = reportRecords;
    }

    @Override
    public String toString() {
        return "DDAReport{" +
                "reportId='" + reportId + '\'' +
                ", reportName='" + reportName + '\'' +
                ", reportGenerationDate='" + reportGenerationDate + '\'' +
                ", reportingDate='" + reportingDate + '\'' +
                ", recordCount='" + recordCount + '\'' +
                ", version='" + version + '\'' +
                ", reportRecords=" + reportRecords +
                '}';
    }
}
